@extends('cms/system/admin/template/theme_default/common')
@section('page-body')
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header layui-form layuiadmin-card-header-auto">
                <!--region 搜索部分-->
                <!--endregion-->
            </div>
            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-list" data-type="deleteFunc">删除</button>
                    <button class="layui-btn layuiadmin-btn-list" data-type="createFunc">添加</button>
                </div>
                <table id="love-unit-list" lay-filter="love-unit-list"></table>
                @verbatim
                    <script type="text/html" id="examine-status">
                        {{#  if (d.examine == 1) { }}
                        <button class="layui-btn layui-btn-xs" lay-event="examineFunc">已通过</button>
                        {{#  } else if (d.examine == 2) { }}
                        <button class="layui-btn layui-btn-primary layui-btn-xs" lay-event="examineFunc">待审核</button>
                        {{#  } }}
                    </script>
                    <script type="text/html" id="manage-status">
                        {{#  if (d.manage_id) { }}
                        <button class="layui-btn layui-btn-xs">已绑定</button>
                        {{#  } else { }}
                        <button class="layui-btn layui-btn-primary layui-btn-xs">未绑定</button>
                        {{#  } }}
                    </script>
                @endverbatim
                <script type="text/html" id="love-unit-list-action">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateFunc"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detailFunc"><i class="layui-icon layui-icon-release"></i>详情</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="deleteFunc"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        layui.config({
            base: '/layui-admin/'
        }).extend({
            index: 'lib/index'
        }).use(['index'], function () {
            // 定义操作列表
            var actionList = {
                // 创建
                createFunc: function () {
                    layer.open({
                        type: 2,
                        title: '添加',
                        content: layui.setter.mvcLink + '/love/admin_unit/create?app={{$app['id'] ?? 0}}',
                        maxmin: true,
                        area: ['550px', '550px'],
                        btn: ['确定', '取消'],
                        yes: function (index, layerWindow) {
                            // 点击确认触发 iframe 内容中的按钮提交
                            var submit = layerWindow.find('iframe').contents().find('#submit-create');
                            submit.click();
                        }
                    });
                },
                // 更新
                updateFunc: function (data) {
                    layer.open({
                        type: 2,
                        title: '更新',
                        content: layui.setter.mvcLink + '/love/admin_unit/update?app={{$app['id'] ?? 0}}&id=' + data.id,
                        maxmin: true,
                        area: ['550px', '550px'],
                        btn: ['确定', '取消'],
                        yes: function (index, layerWindow) {
                            // 点击确认触发 iframe 内容中的按钮提交
                            var submit = layerWindow.find('iframe').contents().find('#submit-update');
                            submit.click();
                        }
                    });
                },
                // 详情
                detailFunc: function (data) {
                    layer.open({
                        type: 2,
                        title: '详情',
                        content: layui.setter.mvcLink + '/love/admin_unit/detail?app={{$app['id'] ?? 0}}&id=' + data.id,
                        maxmin: true,
                        area: ['550px', '550px']
                    });
                },
                // 审核
                examineFunc: function (data) {
                    console.log('审核操作：', data);
                },
                // 删除
                deleteFunc: function (data) {

                }
            };
            // 监听操作按钮
            layui.$('.layui-btn.layuiadmin-btn-list').on('click', function () {
                var actionFunc = layui.$(this).data('type');
                actionList[actionFunc] ? actionList[actionFunc].call(this) : '';
            });
            // 渲染列表
            layui.table.render({
                elem: '#love-unit-list',
                url: layui.setter.apiLink + '/love/admin_unit/retrieve?app={{$app['id'] ?? 0}}',
                parseData: function (result) {
                    return {
                        code: result.code == 1 ? 0 : 1,
                        msg: result.msg,
                        count: result.data.total,
                        data: result.data.items
                    }
                },
                cols: [[
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: 80, title: 'ID', sort: true},
                    {field: 'name', title: '名称'},
                    {field: 'type', title: '类别'},
                    {field: 'address', title: '地址'},
                    {field: 'telephone', title: '电话'},
                    {field: 'examine', title: '审核状态', templet: '#examine-status', minWidth: 80, align: 'center'},
                    {field: 'manage_id', title: '管理员', templet: '#manage-status', minWidth: 80, align: 'center'},
                    {field: 'create_time', title: '添加时间', sort: true},
                    {title: '操作', minWidth: 300, align: 'center', fixed: 'right', toolbar: '#love-unit-list-action'}
                ]],
                page: true,
                limit: 10,
                limits: [10, 15, 20, 25, 30],
                text: '数据加载异常！'
            });
            // 列表操作
            layui.table.on('tool(love-unit-list)', function (object) {
                console.log('监听操作', object);
                var data = object.data;
                actionList[object.event] ? actionList[object.event].call(this, data) : '';
            });
        });
    </script>
@endsection